//
//  HDBDemoViewController.swift
//  HDBWeibo
//
//  Created by leidon on 2016/11/21.
//  Copyright © 2016年 BONC. All rights reserved.
//

import UIKit

class HDBDemoViewController: HDBBaseViewController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "第\(navigationController?.childViewControllers.count ?? 0)页"
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        print("跳转到了push页面")
    }
}

extension HDBDemoViewController{
    
    //重写父类的方法，右侧加 ”下一页“ BarButtonItem
    override func setupUI() {
        super.setupUI()  //父类的方法中，有自定义的背景颜色
        //方法一：系统自带的方法中，页面转换会有高亮效果，若要优化 做好的方法 是自定义重写之
//        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "下一页", style: UIBarButtonItemStyle.plain, target: self, action: #selector(nextPage))
        
        //方法二：swift 调用 OC 的instancetype 是判断不出来是否可选的，所以在barBtn后面加个UIButton 类似于懒加载的方式，就避免了解包
//        let barBtn : UIButton = UIButton.cz_textButton("下一页", fontSize: 13, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange, backgroundImageName: nil)
//        barBtn.addTarget(self, action: #selector(nextPage), for: UIControlEvents.touchUpInside)
//        navigationItem.rightBarButtonItem = UIBarButtonItem(customView: barBtn)
        
        //多次使用就抽取一下～ Extension
        naviItem.rightBarButtonItem = UIBarButtonItem(title: "下一页", target: self, action: #selector(nextPage))
    }
    
    @objc private func nextPage()  {
        let vc = HDBDemoViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
    
}
